package yja.gzw.app.activity

import android.content.Intent
import android.util.Log
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import yja.gzw.app.GenerateTestUserSig
import yja.gzw.app.R
import yja.gzw.app.base.BaseActivity
import yja.gzw.app.databinding.ActivityTopshowBinding
import yja.gzw.app.fragmentview.HomeFragment
import yja.gzw.app.fragmentview.WodeFragment
import yja.gzw.app.fragmentview.XiaoxiFragment
import yja.gzw.app.viewmodel.Mainviewmodel
import com.google.android.material.tabs.TabLayout
import com.tencent.imsdk.v2.V2TIMConversation
import com.tencent.qcloud.tuicore.TUIConstants
import com.tencent.qcloud.tuicore.TUILogin
import com.tencent.qcloud.tuicore.interfaces.TUICallback
import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity
import yja.gzw.app.model.UserData

class TopshowActivity :BaseActivity<Mainviewmodel, ActivityTopshowBinding>(R.layout.activity_topshow){
    val list_fragment= mutableListOf<Fragment>(
      HomeFragment(),XiaoxiFragment(),WodeFragment()
    )
    val listtlit= mutableListOf<String>("首页","消息","我的")
    val tuut= mutableListOf<Int>(R.mipmap.home,R.mipmap.xiaoxi2,R.mipmap.wode2)
    val tuut2= mutableListOf<Int>(R.mipmap.shouye2,R.mipmap.xiaoxi2,R.mipmap.wode2)
    val tuut1= mutableListOf<Int>(R.mipmap.home,R.mipmap.xiaoxitubiao,R.mipmap.wode)


    override fun initView() {

        binding.liushixiangying.setOnClickListener {
            val inten=Intent(this,LishixiangyingActivity::class.java)
            startActivity(inten)

        }


        Log.e("读取用户id2", UserData.id)

        var miyao=  GenerateTestUserSig.genTestUserSig(UserData.id)
        TUILogin.login(this, 1600072775,UserData.id,miyao, object : TUICallback() {
            override fun onSuccess() {
//                Toast.makeText(this@TopshowActivity, "成功", Toast.LENGTH_SHORT).show()
//
//
//                val intent = Intent(this@TopshowActivity, TUIC2CChatActivity::class.java)
//                intent.putExtra(TUIConstants.TUIChat.CHAT_ID, "4");
//                intent.putExtra(TUIConstants.TUIChat.CHAT_TYPE, V2TIMConversation.V2TIM_C2C)
//                startActivity(intent)

            }

            override fun onError(code: Int, desc: String) {
                Toast.makeText(this@TopshowActivity, "失败", Toast.LENGTH_SHORT).show()
                Log.e("登录错误信息",desc)
            }
        })



        binding.viewpagerShow.adapter=object : FragmentPagerAdapter(supportFragmentManager){
            override fun getCount(): Int {

                return list_fragment.size

            }

            override fun getItem(position: Int): Fragment {

                return list_fragment[position]

            }

            override fun getPageTitle(position: Int): CharSequence {
                return listtlit[position]
            }

        }

        binding.tabs.setupWithViewPager(binding.viewpagerShow)



        binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab) {
                tab.setIcon(tuut1[tab.position])

            }

            override fun onTabUnselected(tab: TabLayout.Tab) {

                    tab.setIcon(tuut2[tab.position])
            }

            override fun onTabReselected(tab: TabLayout.Tab?) {

            }




        })

        for (i in 0  until tuut.size ){

                binding.tabs.getTabAt(i)?.setIcon(tuut[i])

        }



    }

    override fun dataObservese() {


    }
}